package com.wf.ew.system.service.impl;

import com.wf.ew.common.JsonResult;
import com.wf.ew.system.biz.RoleBiz;
import com.wf.ew.system.biz.UserBiz;
import com.wf.ew.system.model.Role;
import com.wf.ew.system.dao.RoleMapper;
import com.wf.ew.system.model.User;
import com.wf.ew.system.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author wangfan
 * @since 2019-02-11
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Autowired
    private RoleBiz roleBiz;

    @Override
    public List<Role> listByUserId(Integer userId) {
        return baseMapper.listByUserId(userId);
    }

    @Override
    public Role getByUserId(Integer userId) {
        return baseMapper.getByUserId(userId);
    }

    @Override
    public List<Role> list(Role role, User loginUser){
        return roleBiz.list(role, loginUser);
    }
    @Transactional
    @Override
    public JsonResult add(Role role, User loginUser) {
        if (roleBiz.add(role, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }
}
